home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1997 #3 / Amiga Plus CD - 1997 - No. 03.iso / pd / demo-versionen / maxoncpp4-demo / demo / supercode / menu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-01  |  3.5 KB  |  167 lines

  1. //-------------------------------------
  2. //
  3. // SuperCode (c) 1996 by T.Kühn 
  4. //
  5. // Programmiersprache:    ANSI-C
  6. // Projektstart:            27.12.94
  7. //
  8. // Modul:                MenuHandling.c
  9. //
  10. //-------------------------------------
  11.  
  12.  
  13.  
  14. //-------------------------------------
  15. #include <pragma/gadtools_lib.h>
  16. #include <libraries/gadtools.h>
  17.  
  18. #include <Struct.h>
  19. //-------------------------------------
  20.  
  21.  
  22.  
  23. //-------------------------------------
  24. // VARS
  25. //------------------------------------
  26.  
  27. #define NM_BAR        IM_ITEM,-1,0
  28.  
  29. struct tkMenu Menu_Main;
  30. struct tkNewMenu Desc_Main[]=
  31. {
  32.     {NM_TITLE,    TXT_MENUPROGRAM,                                            },
  33.     {NM_ITEM,    TXT_MENUNEWGAME,        supercode_newgame                },
  34.     {NM_ITEM,    TXT_MENUNEWPLAYER,    supercode_newplayer            },
  35.     {NM_BAR                                                                        },
  36.     {NM_ITEM,    TXT_MENUGIVEUP,        supercode_giveup                },
  37.     {NM_BAR                                                                        },
  38.     {NM_ITEM,    TXT_MENUGAMELOAD,        supercode_loadgame            },
  39.     {NM_ITEM,    TXT_MENUGAMESAVE,        supercode_savegame            },
  40.     {NM_BAR                                                                        },
  41.     {NM_ITEM,    TXT_MENUHIGHSCORES,    score_display                    },
  42.     {NM_ITEM,    TXT_MENUABOUT,            supercode_about                },
  43.     {NM_BAR                                                                        },
  44.     {NM_ITEM,    TXT_MENUQUIT,            Quit                                },
  45.  
  46.     {NM_TITLE,    TXT_MENUSETTINGS,                                            },
  47.     {NM_ITEM,    TXT_MENUSETTINGS,        prefs_windowopen                },
  48.     {NM_BAR                                                                        },
  49.     {NM_ITEM,    TXT_MENUPREFSLOAD,    (APTR)prefs_load                },
  50.     {NM_ITEM,    TXT_MENUPREFSSAVE,    prefs_save                        },
  51.     {NM_END                                                                        }
  52. };
  53.  
  54. struct tkList Head_Menu;
  55.  
  56. //-------------------------------------
  57.  
  58.  
  59.  
  60. //-------------------------------------
  61. BOOL Menu_Create(struct tkMenu *Menu,struct tkNewMenu *NewMenu)
  62. {
  63.     ULONG c,Num=0;
  64.     struct tkNewMenu *Src;
  65.     struct NewMenu *Dst;
  66.     UBYTE *Txt;
  67.     BOOL Back=FALSE;
  68.  
  69.     while(NewMenu[Num].Type) Num++;
  70.  
  71.     if (Num>0)
  72.     {
  73.         Menu->OrgMenu=NewMenu;
  74.  
  75.         List_AddTail(&Head_Menu,&Menu->Node);
  76.         Menu->Number=Num;
  77.         Menu->Mem=(struct NewMenu *)Memory_Alloc( (Num+1) * sizeof(struct NewMenu));
  78.         if (Menu->Mem)
  79.         {
  80.             for(c=0;c<Num;c++)
  81.             {
  82.                 Src=&NewMenu[c];
  83.                 Dst=&Menu->Mem[c];
  84.  
  85.                 Dst->nm_Type=Src->Type;
  86.                 if (Src->Type&MENU_IMAGE)
  87.                 {
  88.                     Dst->nm_Label=(STRPTR)Src->LocText;
  89.                 }
  90.                 else
  91.                 {
  92.                     Txt=CatStr(Src->LocText);
  93.                     if (Txt[1]=='|')
  94.                     {
  95.                         Src->CommKey[0]=Txt[0];
  96.                         Dst->nm_CommKey=Src->CommKey;
  97.                         Txt+=2;
  98.                     }
  99.                     Dst->nm_Label=Txt;
  100.                 }
  101.                 Dst->nm_UserData=Src;
  102.                 Dst->nm_Flags=0;
  103.  
  104.                 if (Src->Type==NM_ITEM && !Src->Func) Dst->nm_Flags|=NM_ITEMDISABLED;
  105.  
  106.                 if (Src->Toggle) Dst->nm_Flags|=CHECKIT|MENUTOGGLE;
  107.             }
  108.             Dst[c].nm_Type=0;
  109.  
  110.             Menu->Menu = CreateMenus(Menu->Mem,
  111.                 GTMN_FullMenu,TRUE,
  112.         //        GTMN_SecondaryError,,
  113.                 TAG_END);
  114.  
  115.         }
  116.     }
  117.     return(Back);
  118. }
  119. //-------------------------------------
  120. VOID Menu_FreeOne(struct tkMenu *Menu)
  121. {
  122.     if (Menu)
  123.     {
  124.         if (Menu->Menu) FreeMenus(Menu->Menu);
  125.         if (Menu->Mem)  Memory_Free((UBYTE**)&Menu->Mem);
  126.     }
  127. }
  128. //-------------------------------------
  129.  
  130.  
  131. //-------------------------------------
  132. VOID Menu_Layout()
  133. {
  134.     BOOL back=0;
  135.     struct tkMenu *menu=(APTR)Head_Menu.lh_Head;
  136.  
  137.     for (;menu->Node.ln_Succ;menu=(APTR)menu->Node.ln_Succ)
  138.     {
  139.         do    {    back=LayoutMenus(menu->Menu,Scrn.Visual,
  140.                     GTMN_TextAttr,Scrn.Scrn->Font,
  141.                     GTMN_NewLookMenus,TRUE,
  142.                     TAG_END);
  143.             } while((!back) && ASK_AGAIN==display_error(ERR_MENU,ASK_EXIT|ASK_AGAIN|ASK_CONT))
  144.     }
  145. }
  146. //-------------------------------------
  147. VOID Menu_Init()
  148. {
  149.     List_Init(&Head_Menu,NT_Menu,0);
  150.  
  151.     Menu_Create(&Menu_Main,Desc_Main);
  152.  
  153. }
  154. //-------------------------------------
  155. VOID Menu_Free()
  156. {
  157.     struct tkMenu *menu=(APTR)Head_Menu.lh_Head;
  158.  
  159.     for (;menu->Node.ln_Succ;menu=(APTR)menu->Node.ln_Succ)
  160.     {
  161.         Menu_FreeOne(menu);
  162.     }
  163. }
  164. //-------------------------------------
  165.  
  166.  
  167.